package adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import app.com.myapplication.Country;
import app.com.myapplication.R;

/**
 * Created by Max on 05.02.2015.
 */
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {

    private LayoutInflater inflater;
    private List<Country> countryList;

    public RecyclerViewAdapter(Context context, List<Country> list) {
        inflater = LayoutInflater.from(context);
        countryList = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.custom_row, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Country country = countryList.get(position);
        holder.countryName.setText(country.getCountryName());
        holder.countryCapital.setText(country.getCountryCapital());
    }

    @Override
    public int getItemCount() {
        return countryList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        TextView countryName;
        TextView countryCapital;

        public ViewHolder(View itemView) {
            super(itemView);

            countryName = (TextView) itemView.findViewById(R.id.countryName);
            countryCapital = (TextView) itemView.findViewById(R.id.countryCapital);
        }
    }
}